package WorkATM;

import Classwork.Ball;

import java.util.Scanner;

public class Message {
    private Date [][] userMessage= {
            {new Date("usera"),new Date("111111"),new Date("1000")},
            {new Date("userb"),new Date("222222"),new Date("2000")},
            {new Date("userc"),new Date("333333"),new Date("3000")},
            {new Date("userd"),new Date("444444"),new Date("4000")}
    };
    private Date [][] ipt= new Date[1][2];
    private Scanner sc=new Scanner(System.in);
    private int using=0;
    private int zhuan=0;
    public Message(){
        process();
    }
    public int getUsing(){
        return this.using;
    }
    public int getzhuan(){
        return this.zhuan;
    }
    public void setUsing(int using){
        this.using=using;
    }
    public void setUsing(int zhuan) {
        this.zhuan = zhuan;
    }


    public static void process(){
        System.out.println("welcome!");
        while(true){
            login();
            menu();
        }
    }
    public static void login( ) {
        for (int j = 0; j < 3; j++) {

            System.out.println("请输入账号");
            ipt[0][1] = new Date(sc.next());
            System.out.println("请输入密码");
            String pwd = sc.next();
            for (int i = 0; i < users.length; i++) {
                if (users[i][0].equals(account) && users[i][1].equals(pwd)) {
                    System.out.println("登陆成功");
                    using=i;
                    return ;
                }
            }
            System.out.println("登陆失败还剩"+(2-j)+"次");
        }
        System.out.println("次数已经被用完");
        System.exit(0);     //弹出程序
    }
    public static void menu(){
        while(true) {
            System.out.println("请选择 1查询,2存款,3取款,4转账,5切换账号,6退出,7出口");
            int imput = sc.nextInt();
            if (imput == 1) {
                search();
            }
            if (imput == 2) {
                save();
            }
            if (imput == 3) {
                get();
            }
            if (imput == 4) {
                transfer();
            }
            if (imput == 5) {

                login();
            }
            if (imput == 6) {
                System.exit(0);

            }
            if (imput==7){
                return;
            }
            else {
                System.out.println("输入有误");
            }

        }
    }
    public static void save(){
        System.out.println("请输入存额");
        double money=sc.nextDouble();
        users[using][2]=Double.parseDouble(users[using][2])+money+"";
        System.out.println("存款成功！");
    }
    public static void get(){
        System.out.println("请输入取款额");
        double money=sc.nextDouble();
        if(Double.parseDouble(users[using][2])>=money){
            users[using][2]=Double.parseDouble(users[using][2])-money+"";
        }
        else{
            System.out.println("输入额度有误，请重新输入");
        }
    }
    public static void search(){
        int c=using;
        System.out.println(users[c][2]);
    }
    public static void transfer() {
        System.out.println("请输入转移账号");
        String  acoun = sc.next();
        for (int i = 1; i < users.length; i++){
            if(users[i][0].equals(acoun)){
                zhuan=i;
                System.out.println("请输入额");
                double money = sc.nextDouble();
                if (Double.parseDouble(users[using][2]) >= money) {
                    users[using][2] = Double.parseDouble(users[using][2]) - money + "";
                    users[zhuan][2] = Double.parseDouble(users[zhuan][2]) + money + "";
                }
                else {
                    System.out.println("输入额度有误，请重新输入");

                }
                return;
            }
            else{
                System.out.println("账户输入错误，请重输入");
                return;
            }
        }
    }








    public void main(String []args){

    }
}
